<?php
  /** Affichage de résultats des tests pour un joueur
   * @author Thomas Bayer
   */
   
   
 class fPlayerTestsDisplayTeam extends aSubFeature {


   public function __construct() {
      $this->_acl = new AccessControlList();
      $this->_acl->setGranted(7);
      $this->_acl->setGranted(3);
   }

   // public static function getTocEntry() {
      // return "Créer une fiche de tests";
   // }

   // public static function getRealName() {
		// return "Afficher une fiche de tests";
	// }
	
	// public static function getSemantic() {
		// $res  = "Cette fonctionnalité permet d'afficher les résultats des tests pour un joueur";
		// return $res;
	// }

	protected function run() {
		return $this->displayForm();
	}
	
	private function displayForm() {
		$birthYear = intval(PropRetriever::getProp($_GET, "y"));
		$gender = PropRetriever::getProp($_GET, "g");
		try {
			$aMember = Member::readYear($birthYear, $gender);
		}
		catch(Exception $e) {
			$pagee = "<h1>Une erreur fatale est survenue ! </h1><br /> <br />"; 
			$pagee .= "<div align=\"center\"> <span class=\"error\">";
			$pagee .= "Il n'y a aucun joueur de sexe $gender né en $birthYear";
			$m1 = new Member();
			$m2 = new Member();
			$aMember = array ($m1, $m2);
		}
		$text1 = "";
		$text2 = "";
		$val = array();
		$tempN = array();
		$tempD = array();
		$ord = 0;
		$temp1 = $temp2 = $temp3 = $temp4 = $temp5 = $temp6 = $temp7 = $temp8 = $temp9 = $temp10 = array();
		$temp11 = $temp12 = $temp13 = $temp14 = $temp15 = $temp16 = $temp17 = $temp18 = $temp19 = $temp20 = array();
		$count = count($aMember) -1 ;
		$nb = 0;
		$errors = -1;
		$page = "<h1> Affichage des tests des joueurs nés en $birthYear </h1>";
		
		for ($n = 0; $n <= $count; $n++) {

			$memberId = $aMember[$n]->getBalloonId();
			try {
				$aPlayerTests = PlayerTests::read($memberId);
				}
			catch (Exception $e) {
				$errors++;
				continue;
				}
			$playerName = $aPlayerTests->displayShort();
			$table = $aPlayerTests->displayLine();
			$ord = intval($table[0]);
			array_push($tempN, $table[1][0]);
			array_push($tempD, $table[2][0]);
			array_push($temp1, $table[3][0]);
			array_push($temp2, $table[4][0]);
			array_push($temp3, $table[5][0]);
			array_push($temp4, $table[6][0]);
			array_push($temp5, $table[7][0]);
			array_push($temp6, $table[8][0]);
			array_push($temp7, $table[9][0]);
			array_push($temp8, $table[10][0]);
			array_push($temp9, $table[11][0]);
			array_push($temp10, $table[12][0]);
			array_push($temp11, $table[13][0]);
			array_push($temp12, $table[14][0]);
			array_push($temp13, $table[15][0]);
			array_push($temp14, $table[16][0]);
			array_push($temp15, $table[17][0]);
			array_push($temp16, $table[18][0]);
			array_push($temp17, $table[19][0]);
			array_push($temp18, $table[20][0]);
			array_push($temp19, $table[21][0]);
			array_push($temp20, $table[22][0]);			
		}
		
		array_push($val, $tempN, $tempD);
		array_push($val, $temp1, $temp2, $temp3, $temp4, $temp5, $temp6, $temp7, $temp8, $temp9, $temp10);
		array_push($val, $temp11, $temp12, $temp13, $temp14, $temp15, $temp16, $temp17, $temp18, $temp19, $temp20);
		if ($ord == 1 
		|| $ord == 3
		|| $ord == 4
		|| $ord == 5
		|| $ord == 6
		|| $ord == 7
		|| $ord == 8
		|| $ord == 9 
		|| $ord == 21) {
			array_multisort($val[$ord], SORT_DESC, $val[0], $val[1], $val[2], $val[3], $val[4], $val[5], $val[6], $val[7], $val[8], $val[9], $val[10],
							$val[11], $val[12], $val[13], $val[14], $val[15], $val[16], $val[17], $val[18], $val[19], $val[20], $val[21]);
		} else {
			array_multisort($val[$ord], SORT_ASC, $val[0], $val[1], $val[2], $val[3], $val[4], $val[5], $val[6], $val[7], $val[8], $val[9], $val[10],
							$val[11], $val[12], $val[13], $val[14], $val[15], $val[16], $val[17], $val[18], $val[19], $val[20], $val[21]);
		}
		$nb = sizeof($val[0]) - 1;

		
		for ($i = 0; $i <= $nb; $i++) {
			$name = $val[0][$i];
			$date = $val[2][$i];
			$height = $val[3][$i];
			$weight = $val[4][$i];
			$fatMass = $val[5][$i];
			$jongleD = $val[6][$i];
			$jongleG = $val[7][$i];
			$jongleT = $val[8][$i];
			$jump = $val[9][$i];
			$speed10m = $val[10][$i];
			$speed20m = $val[11][$i];
			$speed40m = $val[12][$i];
			$orientD = $val[13][$i];
			$orientG = $val[14][$i];
			$amortiD = $val[15][$i];
			$amortiG = $val[16][$i];
			$faceD = $val[17][$i];
			$faceG = $val[18][$i];
			$slalomD = $val[19][$i];
			$slalomG = $val[20][$i];
			$head = $val[21][$i];
			$text1 .= <<<EOS
<tr>
	<th> $name </th>
	<td> $date </td>
	<td> $height </td> 
	<td> $weight </td> 
	<td> $fatMass </td> 
	<td> $jump </td> 
	<td> $speed10m </td> 
	<td> $speed20m </td> 
	<td> $speed40m </td> 
	<td> $head </td>
</tr>
EOS;
		$text2 .= <<<EOS
<tr>
	<th> $name </th>
	<td> $date </td>
	<td> $jongleD </td> 
	<td> $jongleG </td> 
	<td> $jongleT </td>  
	<td> $orientD </td> 
	<td> $orientG </td> 
	<td> $amortiD </td> 
	<td> $amortiG </td> 
	<td> $faceD </td> 
	<td> $faceG </td> 
	<td> $slalomD </td> 
	<td> $slalomG </td>
</tr>
EOS;
		}
		
		if (isset ($pagee)) {
			return $pagee;
		} else if ($errors == $count) {
			$text = "<p>Pas de tests pour les joueurs de sexe $gender nés en $birthYear</p>";
			$page .= $text;
			return $page;
		} else {
			$page .= <<<EOS
<div align="center">
<table class="resultset">
<tr>
	<th rowspan = 2>Tests physiques</th> 
	<th rowspan = 2> <a href="web_fPlayerTestsDisplayTeam.php?y=$birthYear&g=$gender&order=1">Date des tests</a> </th> 
	<th rowspan = 2> <a href="web_fPlayerTestsDisplayTeam.php?y=$birthYear&g=$gender&order=3">Taille</a> </th> 
	<th rowspan = 2> <a href="web_fPlayerTestsDisplayTeam.php?y=$birthYear&g=$gender&order=4">Poids</a> </th> 
	<th rowspan = 2> <a href="web_fPlayerTestsDisplayTeam.php?y=$birthYear&g=$gender&order=5">Masse grasse</a> </th>
	<th rowspan = 2> <a href="web_fPlayerTestsDisplayTeam.php?y=$birthYear&g=$gender&order=9">Détente</a> </th>
	<th colspan = "3"> Vitesse </th> 
	<th rowspan = 2> <a href="web_fPlayerTestsDisplayTeam.php?y=$birthYear&g=$gender&order=21">Jeu de tête</a> </th>
</tr>
<tr>
	<th> <a href="web_fPlayerTestsDisplayTeam.php?y=$birthYear&g=$gender&order=10">10m</a> </th> 
	<th> <a href="web_fPlayerTestsDisplayTeam.php?y=$birthYear&g=$gender&order=11">20m</a> </th> 
	<th> <a href="web_fPlayerTestsDisplayTeam.php?y=$birthYear&g=$gender&order=12">40m</a> </th> 
</tr>
$text1
</table>
<br />
<br />
<br />
</div>

EOS;

		$page .= <<<EOS
<div align="left">
<table class="resultset">
<tr>
	<th rowspan = 2>Tests techniques</th> 
	<th rowspan = 2> <a href="web_fPlayerTestsDisplayTeam.php?y=$birthYear&g=$gender&order=1">Date des tests</a> </th>
	<th colspan = "3"> Jongles </th>
	<th colspan = "2"> Cont orienté + Jeu court </th>
	<th colspan = "2"> Amorti + Jeu long </th> 
	<th colspan = "2"> Cont face + Tir </th> 
	<th colspan = "2"> Slalom 20m </th>
</tr>
<tr>
	<th> <a href="web_fPlayerTestsDisplayTeam.php?y=$birthYear&g=$gender&order=6">D</a> </th> 
	<th> <a href="web_fPlayerTestsDisplayTeam.php?y=$birthYear&g=$gender&order=7">G</a> </th> 
	<th> <a href="web_fPlayerTestsDisplayTeam.php?y=$birthYear&g=$gender&order=8">T</a> </th>
	<th> <a href="web_fPlayerTestsDisplayTeam.php?y=$birthYear&g=$gender&order=13">D</a> </th> 
	<th> <a href="web_fPlayerTestsDisplayTeam.php?y=$birthYear&g=$gender&order=14">G</a> </th>
	<th> <a href="web_fPlayerTestsDisplayTeam.php?y=$birthYear&g=$gender&order=15">D</a> </th> 
	<th> <a href="web_fPlayerTestsDisplayTeam.php?y=$birthYear&g=$gender&order=16">G</a> </th> 
	<th> <a href="web_fPlayerTestsDisplayTeam.php?y=$birthYear&g=$gender&order=17">D</a> </th> 
	<th> <a href="web_fPlayerTestsDisplayTeam.php?y=$birthYear&g=$gender&order=18">G</a> </th> 
	<th> <a href="web_fPlayerTestsDisplayTeam.php?y=$birthYear&g=$gender&order=19">D</a> </th> 
	<th> <a href="web_fPlayerTestsDisplayTeam.php?y=$birthYear&g=$gender&order=20">G</a> </th> 
</tr>
$text2
</table>
</div>

EOS;

			return $page;
		}
	}

} 

   
?>